<?php
    session_start();
    require_once 'php/database.php';
    require_once 'php/photo.php';

    function curPageURL() {
         $pageURL = 'http';
         if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
         $pageURL .= "://";
         if ($_SERVER["SERVER_PORT"] != "80") {
          $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
         } else {
          $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
         }
         return $pageURL;
    }

    function getUserNamePage(){
        if (isset($_SESSION['username']))
	{
		$login = true;
	}
	else{
		$login = false;
		//header("Location: ".$CFG->url."home.php");
	}
	$loguname = $_SESSION['username'];
	$username = $_GET["un"];
	if ($username==NULL&&$login){
		$username=$loguname;
	}
        return $username;
    }
?>

<?php
            $usr = getUserNamePage();
            echo '<form action="php/editprofile.php?un='.$usr.'" method="post" name="editprofile" id="editprofile">';
            echo '<input type="hidden" value="editprofile" name="operation"/>';

                echo '<div id="editform" class="boxy">';
                        echo '<p class="judul">Edit your profile below.</p>';

                            $pemilik = $_SESSION['username'];
                            $con = mysql_connect("localhost", "progin", "progin");
                            if (!$con)
                                    die('Could not connect: ' . mysql_error());

                            mysql_select_db("progin", $con);

                            $hasil = mysql_query("SELECT * FROM user WHERE Username = '$pemilik'", $con);
                            $count = 0;
                            if(mysql_num_rows($hasil)>0){
                                $baris = mysql_fetch_row($hasil);
                                $nama = $baris[3];
                                $email = $baris[4];
                                $tanggal = $baris[5];
                                $hakakses_ = $baris[7];
                                if ($hakakses_ == 0){
                                    $hakakses = "Only me";
                                }
                                else if ($hakakses_ == 1){
                                    $hakakses = "Follower Only";
                                }
                                else if ($hakakses_ == 2){
                                    $hakakses = "Anyone in Foo-Too";
                                }
                                else if ($hakakses_ == 3){
                                    $hakakses = "Everybody";
                                }
                            }

                            echo '<div>';
                                echo '<label>Nama</label>';
                                echo '<input type="text" value="'.$nama.'" id = "nama" name="nama" onblur="hehehe()"/>';
                                echo '<div id = "validasi_nama"><br/></div>';
                            echo '</div>';
                            echo '<div>';
                                echo '<label>Password</label>';
                                echo '<input type="password" value="" id = "password" name="password" onblur="hehehe()"/>';
                                echo '<div id = "validasi_pass"><br/></div>';
                            echo '</div>';
                            echo '<div>';
                                echo '<label>Password Lagi</label>';
                                echo '<input type="password" value="" id = "passwordAgain" onblur="hehehe()"/>';
                                echo '<div id = "validasi_pass2"><br/></div>';
                            echo '</div>';
                            echo '<div>';
                                echo '<label>Email</label>';
                                echo '<input type="text" value="'.$email.'" id = "email" name="email" onblur="hehehe()"/>';
                                echo '<div id = "validasi_email"><br/></div>';
                            echo '</div>';
                            echo '<div>';
                                echo '<label>Hak akses</label>';
                                echo '<select id = "hakakses" name="hakakses" onblur="hehehe()">';

                                        if ($hakakses_ == 0){
                                          echo '<option value="0" SELECTED>Only Me</option>';
                                          echo '<option value="1">Follower Only</option>';
                                          echo '<option value="2">Anyone in Foo-too</option>';
                                          echo '<option value="3">Everybody</option>';
                                        }

                                        else if ($hakakses_ == 1){
                                          echo '<option value="0">Only Me</option>';
                                          echo '<option value="1" SELECTED>Follower Only</option>';
                                          echo '<option value="2">Anyone in Foo-too</option>';
                                          echo '<option value="3">Everybody</option>';
                                        }

                                        else if ($hakakses_ == 2){
                                          echo '<option value="0">Only Me</option>';
                                          echo '<option value="1">Follower Only</option>';
                                          echo '<option value="2" SELECTED>Anyone in Foo-too</option>';
                                          echo '<option value="3">Everybody</option>';
                                        }

                                        else if ($hakakses_ == 3){
                                          echo '<option value="0">Only Me</option>';
                                          echo '<option value="1">Follower Only</option>';
                                          echo '<option value="2">Anyone in Foo-too</option>';
                                          echo '<option value="3" SELECTED>Everybody</option>';
                                        }

                                echo '</select>';
                                echo '<div id = "validasi_email"><br/></div>';
                            echo '</div>';
                            echo '<div>';
                                echo '<label>Tanggal Lahir</label>';
                                echo '<input type="text" value="'.$tanggal.'" size="25" id = "tanggalLahir" name="lahir" onblur="hehehe()"/>';
                                echo '<a href="javascript:NewCal('."'tanggalLahir','yyyymmdd'".')">';
                                   echo '<img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"/>';
                                echo '</a>';
                                echo '<div id = "validasi_tgl"><br/></div>';
                            echo '</div>';
                        
                    echo '<div>';
                        //echo '<button style="margin-left: 450px;" id = "submit" onmouseover="validasi()">Submit</button>';
                        echo '<br/>';
                        echo '<div style="margin-left: 350px;" class="button180" onclick="backToProfile(\''.$user.'\')">Cancel</div>';
                        echo '<br/>';
                        echo '<div style="margin-left: 350px;" class="button180" onclick="submiteditform()" onmouseover="validasi()">Submit</div>';
                    echo '</div>';
                echo '</div>';
            echo '</form>';
?>